const bomMixin = {
  data() {
    return {
      option: {
        calcHeight: 30,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        labelWidth: '130',
        border: true,
        index: true,
        selection: false,
        dialogClickModal: false,
        height: 'calc(100vh - 440px)',
        viewBtn: false,
        delBtn: false,
        addBtn: true,
        indexLabel: '序号',
        columnBtn: false,
        column: [
          {
            label: '编号',
            prop: 'bomNo',
            search: true,
            rules: [
              {
                required: true,
                message: '请输入编号',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '产品编码',
            prop: 'partNo',
            type: 'search',
            disabled: true,
            search: true,
            searchType: 'input',
            appendClick: () => {
              this.openCommonModal('PRODUCT', 'bomTitle');
            },
            rules: [
              {
                required: true,
                message: '请输入产品编码',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '产品名称',
            prop: 'partName',
            disabled: true
          },
          {
            label: '产品型号',
            prop: 'partModel',
            disabled: true
          },
          {
            label: '版本',
            prop: 'bomVersion',
            rules: [
              {
                required: true,
                message: '请输入版本',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '密度',
            prop: 'density',
            type: 'number',
            precision: 2,
            controls: false
          },
          {
            label: '源创建日期',
            prop: 'sourceCreateDate',
            type: 'datetime',
            format: 'yyyy-MM-dd HH:mm:ss',
            valueFormat: 'yyyy-MM-dd HH:mm:ss'
          },
          {
            label: '源数据审核日期',
            prop: 'sourceAduitDate',
            type: 'datetime',
            format: 'yyyy-MM-dd HH:mm:ss',
            valueFormat: 'yyyy-MM-dd HH:mm:ss'
          }
        ]
      },
      partDetailOption: {
        //bom详情配置
        calcHeight: 30,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        labelWidth: '130',
        border: true,
        index: true,
        selection: false,
        dialogClickModal: false,
        tree: true,
        rowKey: 'id',
        rowParentKey: 'parentId',
        children: 'children',
        hasChildren: 'hasChildren',
        lazy: true,
        height: '500',
        viewBtn: true,
        viewBtn: false,
        delBtn: false,
        index: false,
        columnBtn: false,
        refreshBtn: false,
        dialogClickModal: false,
        highlightCurrentRow: true, // 选中高亮
        column: [
          {
            label: '序号',
            prop: 'sort',
            type: 'number',
            controls: false,
            width: 150
          },
          {
            label: '位号',
            prop: 'positionNo',
            display: true,
            controls: false,
            width: 150
          },
          {
            label: '物料编码',
            prop: 'partNo',
            minWidth: 150,
            type: 'search',
            disabled: true,
            appendClick: () => {
              this.openCommonModal('', 'bomDetailTitle');
            },
            rules: [
              {
                required: true,
                message: '请输入物料编码',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '物料名称',
            prop: 'partName',
            disabled: true
          },
          {
            label: '物料型号',
            prop: 'partModel',
            disabled: true
          },
          {
            label: '用量',
            prop: 'unitQty',
            type: 'number',
            controls: false,
            precision: 10,
            width: 150,
            rules: [
              {
                required: true,
                message: '请输入用量',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '单位',
            prop: 'unitNo',
            width: 150,
            type: 'input',
            rules: [
              {
                message: '请输入单位',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '替代料',
            prop: 'isReplacement',
            width: 150,
            type: 'switch',
            value: false,
            dicData: [
              {
                label: '否',
                value: false
              },
              {
                label: '是',
                value: true
              }
            ]
          },
          {
            label: '自产',
            prop: 'isSelfProduction',
            width: 150,
            type: 'switch',
            value: false,
            dicData: [
              {
                label: '否',
                value: false
              },
              {
                label: '是',
                value: true
              }
            ]
          },
          {
            label: '外协',
            prop: 'isOutSource',
            width: 150,
            type: 'switch',
            value: false,
            dicData: [
              {
                label: '否',
                value: false
              },
              {
                label: '是',
                value: true
              }
            ]
          },
          {
            label: '关键料',
            prop: 'isKeyPart',
            width: 150,
            type: 'switch',
            value: false,
            dicData: [
              {
                label: '否',
                value: false
              },
              {
                label: '是',
                value: true
              }
            ]
          }
          // {
          //     label: '上层物料',
          //     prop: 'parentId',
          //     width: 150,
          //     type: 'tree',
          //     dicData: [], // 初始化字典信息，不然数据动态展示不了
          //     display: false,
          //     hide: true,
          //     addDisabled: false,
          //     props: {
          //         // 子集菜单显示
          //         label: 'title'
          //     }
          // }
        ]
      },
      replacePartTableOption: {
        //替代料配置
        calcHeight: 30,
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        labelWidth: '130',
        border: true,
        index: true,
        selection: false,
        dialogClickModal: false,
        height: '400',
        delBtn: true,
        addBtn: false,
        viewBtn: true,
        refreshBtn: false,
        columnBtn: false,
        column: false,
        column: [
          {
            label: '料号',
            prop: 'partNo',
            type: 'search',
            disabled: true,
            appendClick: () => {
              this.openCommonModal('', 'repalceTitle');
            },
            rules: [
              {
                required: true,
                message: '请输入料号',
                trigger: 'blur'
              }
            ],
            span: 8
          },
          {
            label: '替代比例',
            prop: 'subsRate',
            type: 'number',
            value: 1,
            minRows: 1,
            rules: [
              {
                required: true,
                message: '请输入替代比例',
                trigger: 'blur'
              }
            ],
            span: 8
          },
          {
            label: '用量',
            prop: 'useCount',
            span: 8,
            formslot: true,
            disabled: true
          }
        ]
      },
      propertiesOption: {
        labelWidth: '130',
        column: [
          {
            label: '料号',
            prop: 'partNo',
            type: 'search',
            disabled: true,
            appendClick: () => {
              this.openCommonModal('', 'repalceTitle');
            },
            rules: [
              {
                required: true,
                message: '请输入料号',
                trigger: 'blur'
              }
            ],
            span: 8
          },
          {
            label: '替代比例',
            prop: 'subsRate',
            type: 'number',
            value: 1,
            minRows: 1,
            rules: [
              {
                required: true,
                message: '请输入替代比例',
                trigger: 'blur'
              }
            ],
            span: 8
          },
          {
            label: '用量',
            prop: 'useCount',
            span: 8,
            formslot: true,
            disabled: true
          }
        ]
      }
    };
  },
  methods: {
    /**
     * 打开模态框
     */
    openCommonModal(partType, title) {
      const url = partType ? `/api/mes-admin/part-master/page?semifinished=true` : '/api/mes-admin/part-master/page?materialAndSemifinished=true';
      this.$refs.commonModalTemplate.showModal();
      this.tableOption = {
        modalTitle: '选择物料信息（双击进行选择）',
        url,
        isPage: true,
        index: false,
        titleInfo: title,
        rowSelectionType: 'single',
        columnDefs: [
          {
            label: '类型',
            prop: 'categoryId',
            type: 'tree',
            dicUrl: '/api/mes-admin/part-category/tree',
            props: {
              label: 'title',
              value: 'id'
            }
          },
          {
            label: '物料编码',
            prop: 'partNo',
            search: true,
            minWidth: 150
          },
          {
            label: '名称',
            prop: 'name',
            search: true,
            width: 150
          },
          {
            label: '物料型号',
            prop: 'partModel',
            width: 150
          },
          {
            label: '描述',
            prop: 'description',
            width: 150
          },
          {
            label: '版本',
            prop: 'revision',
            width: 150
          }
        ]
      };
    }
  }
};

export default bomMixin;
